package com.flyou.consumer.config;

import com.flyou.consumer.client.UserFeginClient;
import com.flyou.consumer.pojo.User;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @ClassName FeginFallbackFactory.java
 * @author fzl
 * @version 1.0.0
 * @Description FallbackFactory 可以让你获取到服务降级或者熔断的原因
 * @createTime 2022/2/10 14:30
 */
@Component
public class FeignFallbackFactory implements FallbackFactory<UserFeginClient> {


    @Override
    public UserFeginClient create(Throwable cause) {
        return new UserFeginClient() {
            @Override
            public User findUserById(Long id) {
                User user=new User();
                user.setUserName("请求失败了,"+cause.getMessage());
                return user;
            }
        };
    }

}
